package com.example.android.wearable.wear.wearaccessibilityapp;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.example.android.wearable.wear.wearaccessibilityapp.view.AppFragment1;
import com.example.android.wearable.wear.wearaccessibilityapp.view.AppFragment2;

import java.util.ArrayList;

public class AppActivity extends FragmentActivity {
    public ArrayList<Fragment> mFragments = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app);
        mFragments.add(new AppFragment2());
        mFragments.add(new AppFragment1());

        final ViewPager2 viewPager2 = findViewById(R.id.vp2);
        viewPager2.setAdapter(new TestAdapter(this));

    }

    public class TestAdapter extends FragmentStateAdapter {

        public TestAdapter(@NonNull FragmentActivity fragmentActivity) {
            super(fragmentActivity);
        }

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getItemCount() {
            return mFragments.size();
        }
    }
}
